﻿<!DOCTYPE html>
@{
    string ColorTiles = "#", ColorNotification = "#", ColorTilesHover = "#";    
}
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
    <link href="~/Contents/MetroUI/layout_metro.css" rel="stylesheet" />
    <link href="~/Contents/MetroUI/page-metro.css" rel="stylesheet" />
    <link href="~/Contents/MetroUI/detail-metro.css" rel="stylesheet" />
    <link href="~/Contents/farbtastic.css" rel="stylesheet" />
    @if (Request.Cookies["Color"] != null)
    {
        if (!String.IsNullOrEmpty(Request.Cookies["Color"].Values[".tiles"]))
        {
            ColorTiles = Request.Cookies["Color"].Values[".tiles"];
            <style>
                .tiles {
                    background-color:@ColorTiles;
                }
                #color-value-tiles {
                    background-color:@ColorTiles;
                }
            </style>
        }
        if (!String.IsNullOrEmpty(Request.Cookies["Color"].Values[".toast-notification"]))
        {
            ColorNotification = Request.Cookies["Color"].Values[".toast-notification"];
            <style>
                .toast-notification {
                    background-color:@ColorNotification;
                }
                #color-value-notification {
                    background-color:@ColorNotification;
                }
            </style>
        }
        if (!String.IsNullOrEmpty(Request.Cookies["Color"].Values[".tiles-hover"]))
        {
            ColorTilesHover = Request.Cookies["Color"].Values[".tiles-hover"];
            <style>
                .tiles-hover {
                    background-color:@ColorTilesHover;
                }
                #color-value-tiles-hover {
                    background-color:@ColorTilesHover;
                }
            </style>
        }
    }
    <script src="~/Scripts/jquery-1.8.2.js"></script>
    <script src="~/Scripts/jquery.mousewheel.js"></script>
    <script src="~/Scripts/MyJs.js"></script>
    <script src="~/Scripts/jquery.my.ajax.js"></script>
    <script src="~/Scripts/sliderengine/amazingslider.js"></script>
    <script src="~/Scripts/sliderengine/initslider-1.js"></script>
    <script src="~/Scripts/sliderengine/initslider-2.js"></script>
    <script src="~/Scripts/farbtastic.js"></script>
</head>
<body>
    @{
        bool ToastEnable = false;
        try
        {
            ToastEnable = (bool)TempData["ToastEnable"];
        }
        catch { }
        if (ToastEnable)
        {
            string LinkToast = TempData["LinkToast"] != null ? TempData["LinkToast"].ToString() : "javascript: return false";
            <a href="@LinkToast">
                <div class="toast-notification">
                    <div class="left-toast"></div>
                    <div class="message-toast">@Html.Raw(TempData["Message"])</div>
                    <b class="close-toast"></b>
                </div>
            </a>
        }
    } 
    <div id="nav-bar">
        @{
            SnongPhoneShop.Models.SnongPhoneShopEntities db = new SnongPhoneShop.Models.SnongPhoneShopEntities();
        }
        <div class="nav-bar-left">
            <span id="text-h1">SnongPhoneShop - @ViewBag.CurrPage</span>
            <div class="nav-dropdown-menu">
                <ul id="menu">
                    <li><a href="@Url.Action("Index", "Home")"><span>Trang chủ</span></a></li>
                    <li>
                        <a href="@Url.Action("Dien_Thoai", "San_Pham")"><span>Điện thoại<b class="icon-arrow"></b></span></a>
                        <ul>
                            @foreach (var Item in db.DanhMucSanPhams.Where(m => m.Publish == true && m.MaLoaiDanhMuc == 1).OrderBy(m => m.STT).ToList())
                            { 
                                <li><a href="@Url.Action("DM_SanPham", "San_Pham", new { ID = Item.MaDanhMuc })"><span>@Item.TenDanhMuc</span></a></li>
                            }
                        </ul>
                    </li>
                    <li>
                        <a href="@Url.Action("Phu_Kien", "San_Pham")"><span>Phụ kiện<b class="icon-arrow"></b></span></a>
                        <ul>
                            @foreach (var Item in db.DanhMucSanPhams.Where(m => m.Publish == true && m.MaLoaiDanhMuc == 2).OrderBy(m => m.STT).ToList())
                            { 
                                <li><a href="@Url.Action("DM_SanPham", "San_Pham", new { ID = Item.MaDanhMuc })"><span>@Item.TenDanhMuc</span></a></li>
                            }
                        </ul>
                    </li>
                    <li><a href="@Url.Action("Bao_Gia_DT", "San_Pham")"><span>Báo giá</span></a></li>
                    <li><a href="@Url.Action("Gioi_Thieu", "Home")"><span>Giới thiệu</span></a></li>
                    <li id="parent-color-picker">
                        <span title="Tùy biến giao diện" id="customize-theme-btt"></span>
                        <div id="color-picker">
                            <div id="colorpicker"></div>
                            <input type="text" class="color-value color-value-selected" id="color-value-tiles" name="color" value="@ColorTiles" />
                            <input type="text" class="color-value" id="color-value-notification" name="color" value="@ColorNotification" />
                            <input type="text" class="color-value" id="color-value-tiles-hover" name="color" value="@ColorTilesHover" />
                            <div class="panel-target-customize">
                                <select id="list-target-customize">
                                    <option value="1">Tiles</option>
                                    <option value="2">Tiles hover</option>
                                    <option value="3">Notification</option>
                                </select>
                            </div>
                            <script type="text/javascript">
                                $(document).ready(function () {
                                    function setcolor(selector1, selector2) {
                                        var f = $.farbtastic('#colorpicker');
                                        f.linkTo(selector1 + ', ' + selector2);
                                        $(this).mouseup(function (e) {
                                            if ($(e.target).parents('#color-picker').length > 0) {
                                                $.ajax({
                                                    url: '/Ajax/SetCookieColor',
                                                    data: { Selector: selector1, Color: $(selector2).val() },
                                                    cache: false
                                                });
                                            }
                                        });
                                    }

                                    function callback(selector1, selector2) {
                                        $('.color-value').removeClass('color-value-selected');
                                        $(selector2).addClass('color-value-selected');
                                        setcolor(selector1, selector2);
                                    }
                                    setcolor('.tiles', '#color-value-tiles');

                                    $('#list-target-customize').change(function () {
                                        switch ($(this).val()) {
                                            case '1': callback('.tiles', '#color-value-tiles');
                                                break;
                                            case '2': callback('.tiles-hover', '#color-value-tiles-hover');
                                                break;
                                            case '3': callback('.toast-notification', '#color-value-notification');
                                                break;
                                            default: callback('.tiles', '#color-value-tiles');
                                                break;
                                        }
                                    });
                                });
                            </script>
                        </div>
                    </li>
                    <li>
                    @using (Html.BeginForm("Index", "Tim_Kiem"))
                    { 
                        <span id="search-form">
                            @Html.TextBox("Search-Input-In-Layout", null, new { placeholder = "Từ khóa tìm kiếm" })
                            <input type="submit" hidden="hidden" />
                        </span>
                        <div class="quick-result-div">
                            <div class="scroll-enable" id="quick-result-display-layout"></div>
                        </div>
                    }                           
                    </li>
                </ul>
            </div>
        </div>
        <div class="nav-bar-right">
            @{
                string UserName = "";
                int SumGH = 0, NumGH = 0;
                if (Session["Cart"] != null)
                {
                    var LCart = (List<SnongPhoneShop.Models.Cart>)Session["Cart"];
                    SumGH = LCart.Sum(m => m.SoLuong);
                    NumGH = LCart.Count;
                }
                else
                {
                    List<SnongPhoneShop.Models.Cart> LCart = new List<SnongPhoneShop.Models.Cart>();
                    if (Request.Cookies["Cart"] != null)
                    {
                        try
                        {
                            for (int i = 0; i < Request.Cookies["Cart"].Values.Count; i++)
                            {
                                SnongPhoneShop.Models.Cart SP = new SnongPhoneShop.Models.Cart();
                                SP.MaSanPham = Request.Cookies["Cart"].Values.GetKey(i);
                                SP.SoLuong = int.Parse(Request.Cookies["Cart"].Values[i]);
                                LCart.Add(SP);
                            }
                        }
                        catch { }
                    }
                    SumGH = LCart.Sum(m => m.SoLuong);
                    NumGH = LCart.Count;
                    Session.Add("Cart", LCart);
                }
                if (Session["User"] == null && Request.Cookies["Login"] == null)
                {      
                    <div class="login-area">
                        <span id="sign-in">Đăng nhập</span>
                        <b id="icon-shopping-cart" class="icon-info">@NumGH (@SumGH)</b>
                        <div class="sign-form">
                            <span class="valid-login-message"></span>
                            @{
                                string UrlRef = Request.Url.OriginalString;
                            }
                            @using (Html.BeginForm("Dang_Nhap", "Tai_Khoan", new { UrlReferer = UrlRef }, FormMethod.Post))
                            {
                                @Html.TextBox("TenDangNhap", "scopion93", new { placeholder = "Tên đăng nhập" })
                                @Html.Password("MatKhau", "123456", new { placeholder = "Mật khẩu" })
                                @Html.CheckBox("GhiNho", new { id = "remember-check-1" }) <label for="remember-check-1">Ghi nhớ?</label>
                                <input type="submit" value="Đăng nhập" id="btt-submit-sign-in" />
                            }
                            <a href="@Url.Action("Dang_Ky", "Tai_Khoan")"><input type="button" value="Đăng ký" id="btt-register" /></a>
                            <a href="@Url.Action("Quen_Mat_Khau", "Tai_Khoan")"><input type="button" value="Quên mật khẩu" id="btt-forgot-pw" /></a>
                            <a href="@Url.Action("Gio_Hang", "Tai_Khoan")"><input type="button" value="Giỏ hàng" id="btt-cart" /></a>
                        </div>
                    </div>              
                }
                else
                {
                    if (Session["User"] != null)
                    {
                        UserName = Session["User"].ToString();
                    }
                    else
                    {
                        UserName = Request.Cookies["Login"].Values["User"];
                        Session["User"] = UserName;
                    }
                    string UserFullName = db.KhachHangs.First(m => m.TenDangNhap.Equals(UserName)).HoTen;                    
                    <div class="user-info-area">
                        <span id="user-name">
                            @Html.Raw(UserFullName)
                        </span>
                        <b id="icon-shopping-cart" class="icon-info">@NumGH (@SumGH)</b>
                        <div class="user-manager">
                            <dl>
                                <dd><a href="@Url.Action("Index", "Tai_Khoan")"><span>Thông tin tài khoản</span></a></dd>
                                <dd><a href="@Url.Action("Gio_Hang", "Tai_Khoan")"><span>Giỏ hàng</span></a></dd>
                                <dd><a href="@Url.Action("Dang_Xuat", "Tai_Khoan")"><span>Đăng xuất</span></a></dd>
                            </dl>
                        </div>                     
                    </div>
                }
            }
        </div>
    </div>
    <div class="metro-body">
        @RenderBody()
        @{
            List<SnongPhoneShop.Models.SanPham> LRecent = new List<SnongPhoneShop.Models.SanPham>();
            if (Request.Cookies["Recently"] != null)
            {
                var cookie = Request.Cookies["Recently"].Values;
                for (int i = 0; i < cookie.Count; i++)
                {
                    string val = cookie[i];
                    LRecent.Add(db.SanPhams.First(m => m.MaSanPham.Trim().Equals(val)));
                }
            }
        }
        @if (LRecent.Count > 0)
        { 
            <div class="group-tiles">
                <span class="group-name"><a href="@Url.Action("ClearRecently", "Home")" title="Click để xóa toàn bộ">Sản phẩm đã xem gần đây</a></span>
                @for (int i = LRecent.Count - 1; i >= 0; i--)
                {
                    if ((LRecent.Count - 1 - i) % 3 == 0)
                    { 
                        @Html.Raw("<div class=\"column\">")
                    }          
                    <div class="wide-tiles tiles">
                        <span class="title-tiles">@LRecent[i].TenSanPham</span>
                        <img class="img-product" src="@LRecent[i].AnhDaiDien" />
                        <div class="basic-info">
                            <ul>
                                <li>Tình trạng: @LRecent[i].TinhTrang.TenTinhTrang</li>
                                <li>Bảo hành: @LRecent[i].BaoHanh</li>
                                <li>Quà tặng: @LRecent[i].QuaTang</li>
                                <li>Giá bán: @LRecent[i].DonGia.ToString("n0") VND</li>
                            </ul>
                        </div>
                        <div class="wide-tiles tiles-hover">
                            <a href="@Url.Action("CT_SanPham", "San_Pham", new { ID = LRecent[i].MaSanPham.Trim() })"><img class="detail-view" src="/Images/ImgPage/2c_info.png" title="Xem chi tiết" /></a>
                            <a href="@Url.Action("Dat_Hang", "San_Pham", new { ID = LRecent[i].MaSanPham.Trim() })"><img class="add-cart" src="/Images/ImgPage/Very-Basic-Plus-icon.png" title="Thêm giỏ hàng" /></a>
                        </div>
                    </div>
                    if ((LRecent.Count - 1 - i) % 3 == 2 || i == 0)
                    { 
                        @Html.Raw("</div>")
                    }
                }
            </div>
        }
    </div>
</body>
</html>
